/**
 * @class 时间数据代理
 * @author DuskyHuang 圣子
 * @description 提供全局时间、日期、加速相关数据和管理。
*/

import { Proxy, decorators } from 'cfw';
import { Timer } from 'const';
const { singleton } = decorators;

@singleton
export class TimerProxy extends Proxy {

    declare public static readonly instance: TimerProxy;
    private constructor() { super(); }

    private _timer: Timer = 3;
    private _timescale: num.ratio = 15;
    public get timer(): Timer { return this._timer; }
    public get timescale(): num.ratio { return this._timescale; }

    public accelerate(timer: Timer): void {
        this._timer = timer;
        switch (this._timer) {
            case Timer.STOP: this._timescale = 0; break;
            case Timer.SECOND: this._timescale = 0.004167; break;
            case Timer.MINUTE: this._timescale = 0.25; break;
            case Timer.HOUR: this._timescale = 15; break;
            case Timer.DAY: this._timescale = 360; break;
            case Timer.WEEK: this._timescale = 2520; break;
            case Timer.MONTH: this._timescale = 10980; break;
            case Timer.YEAR: this._timescale = 131400; break;
        }
    }

    public stop(): void { this._timescale = 0; }

    public get desc(): string {
        switch (this._timer) {
            case Timer.STOP: return '停止';
            case Timer.SECOND: return '1秒钟';
            case Timer.MINUTE: return '1分钟';
            case Timer.HOUR: return '1小时';
            case Timer.DAY: return '1天';
            case Timer.WEEK: return '1周';
            case Timer.MONTH: return '1月';
            case Timer.YEAR: return '1年';
        }
    }

    protected init(): void { this.accelerate(Timer.HOUR); }
}

export const timer = TimerProxy.instance;